﻿using System;
using FlitBit.Core.Factory;
using FlitBit.Core.Meta;

namespace FlitBit.Cache
{
	/// <summary>
	///   Used by the framework too wireup the default cache eviction manager.
	/// </summary>
	[AttributeUsage(AttributeTargets.Interface | AttributeTargets.Class)]
	public class DefaultCacheEvictionManagerAttribute : AutoImplementedAttribute
	{
		/// <summary>
		///   Creates a new instance.
		/// </summary>
		public DefaultCacheEvictionManagerAttribute()
		{
			RecommemdedScope = InstanceScopeKind.Singleton;
		}

		/// <summary>
		///   Registers the DefaultCacheEvictionMonitor.
		/// </summary>
		public override bool GetImplementation(IFactory factory, Type type, Action<Type, Func<object>> complete)
		{
			if (type != typeof(ICacheEvictionManager))
			{
				throw new ArgumentException(
					"DefaultCacheEvictionManagerAttribute is intended to be used only on the interface ICacheEvictionManager");
			}
			complete(typeof(DefaultCacheEvictionManager), null);
			return true;
		}
	}
}